<?php
namespace app\admin\controller;

use support\Request;

class Site_config extends  Base
{
    /**
     * 初始化
     */
    protected function initialize()
    {
        $this->model = new \app\admin\model\SiteConfig;
    }

    /**
     * 网站设置
     * @param Request $request
     * @return string|\support\Response
     */
    public function web(Request $request)
    {
        $model = $this->model->where('key','web')->field('value')->find();
        if ($request->isAjax()) {
            $model->save(['value'=>$request->post()]);
            return json(['code'=>200,'msg'=>'保存成功']);
        }
        return view('site_config/web', [
            'data' =>  $model['value']
        ]);
    }

    /**
     * 邮箱设置
     * @param Request $request
     * @return string|\support\Response
     */
    public function email(Request $request)
    {
        $model = $this->model->where('key','email')->field('value')->find();
        if ($request->isAjax()) {
            $model->save(['value'=>$request->post()]);
            return json(['code'=>200,'msg'=>'保存成功']);
        }
        return view('site_config/email', [
            'data' =>  $model['value']
        ]);
    }

    /**
     * 上传设置
     * @param Request $request
     * @return string|\support\Response
     */
    public function file(Request $request)
    {
        $model = $this->model->where('key','file')->field('value')->find();
        if ($request->isAjax()) {
            $model->save(['value'=>$request->post()]);
            return json(['code'=>200,'msg'=>'保存成功']);
        }
        return view('site_config/file', [
            'data' =>  $model['value']
        ]);
    }
}
